package com.itheima.controller;

import com.itheima.domain.User;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.Map;

@Controller
@RequestMapping("/param")
public class ParamController {

    @RequestMapping("/test1")
    public String test1(User user,String hobbies){
/*        System.out.println("名称"+user.getUsername()+"-- 年龄"+user.getPassword());

        System.out.println(user.getAddress());*/
        System.out.println(user);
        System.out.println(hobbies);

        return "success";
    }
    @RequestMapping("/test2")
    public String test2(@RequestParam(value = "username",required=true,defaultValue = "123456") String name,
                        @RequestParam(value = "age",required=true,defaultValue = "15")int age){
//        System.out.println("名称"+user.getUsername()+"-- 年龄"+user.getPassword());
        System.out.println(name+"---"+age);
        return "success";
    }


    @RequestMapping("/test3")
    public String test3(Date birthday){
        System.out.println(birthday);
        return "success";
    }

    /*
     * 携带数据响应页面的方式（JSP）：
     *   1、原生ServletAPI(不建议使用：尽量解耦)
     *   2、ModelAndView:  值存入request作用域(不建议使用)
     *   3、Model:          值存入request作用域
     *   4、Map:            值存入request作用域
     *
     *   controller跳转到指定controller
     *      redirect:指定请求URL
     *       重定向（客户端跳转）
     *      forward:指定请求URL
     *       请求转发（服务端跳转）
     * */

    @RequestMapping("/test4")
    public String test4(Model model) {
        model.addAttribute("username","张三");

        return "forward:/user/update";
    }

    @RequestMapping("/test5")
    public String test5(Map map){
        System.out.println("测试");

        map.put("username","heifengli");
        return "main";
    }
}
